/**
 * 系统管理---用户管理模块
 */

var MgrUser = {
    id: "managerTable",
    seItem: null,
    table: null,
    layerIndex: -1,
    deptid:0
};

// 新增用户
MgrUser.openAddMgr = function () {
    var index = layer.open({
        type: 2,
        title: '添加管理员',
        area: ['800px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + ctxPath + 'mgr/user/user_add'
    });
    this.layerIndex = index;
}

/**
 * 检查是否选中
 */
MgrUser.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        MgrUser.seItem = selected[0];
        return true;
    }
};

// 修改
MgrUser.openChangeUser = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改用户信息',
            area: ['800px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + ctxPath + 'mgr/user/user_edit/' + this.seItem.id
        });

        this.layerIndex = index;
    }
}

// 删除
MgrUser.deleteUser = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改用户信息',
            area: ['800px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + ctxPath + 'mgr/user/delete/' + this.seItem.id
        });

        this.layerIndex = index;
    }
}

// 表格栏目初始化
MgrUser.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'ible: false, aligid', field: 'id', visn: 'center', valign: 'middle'},
        {title: '账号', field: 'account', align: 'center', valign: 'middle', sortable: true},
        {title: '姓名', field: 'name', align: 'center', valign: 'middle', sortable: true},
        {title: '性别', field: 'sexName', align: 'center', valign: 'middle', sortable: true},
        {title: '角色', field: 'roleName', align: 'center', valign: 'middle', sortable: true},
        {title: '部门', field: 'deptName', align: 'center', valign: 'middle', sortable: true},
        {title: '邮箱', field: 'email', align: 'center', valign: 'middle', sortable: true},
        {title: '电话', field: 'phone', align: 'center', valign: 'middle', sortable: true},
        {title: '创建时间', field: 'createtime', align: 'center', valign: 'middle', sortable: true},
        {title: '状态', field: 'statusName', align: 'center', valign: 'middle', sortable: true}];

    return columns;
}

MgrUser.search = function () {
    var queryData = {};

    queryData['deptid'] = MgrUser.deptid;
    queryData['name'] = $("#name").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    MgrUser.table.refresh({query: queryData});
}

MgrUser.onClickDept = function (e, treeId, treeNode) {
    MgrUser.deptid = treeNode.id;
    MgrUser.search();
};

$(function () {
    var defaultColunms = MgrUser.initColumn();
    var table = new BSTable("managerTable", ctxPath + "mgr/user/list", defaultColunms);
    table.setPaginationType("client");
    MgrUser.table = table.init();

    var ztree = new $ZTree("deptTree", ctxPath+"dept/tree");
    ztree.bindOnClick(MgrUser.onClickDept);
    ztree.init();
})
